package service.impl.v2;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import dao.v2.ConfigVOMapper;
import dao.v2.SaleVOMapper;
import model.GoodVO;
import model.SaleVO;
import service.v2.MaterialService;
import service.v2.SaleService;

@Service
public class SaleServiceImpl implements SaleService {
	@Autowired
	private SaleVOMapper dao;
	
	@Autowired
	private ConfigVOMapper  configDao;
	@Autowired
	private MaterialService  materialService;
	
	public List<SaleVO> getSaleIndex(SaleVO saleVO) {
		return dao.getSaleIndex(saleVO);
	}
	
	public int getSaleTotal(SaleVO saleVO) {
		return dao.getSaleTotal(saleVO);
	}
	
	public List<SaleVO> getSaleList(SaleVO saleVO) {
		return dao.getSaleList(saleVO);
	}

	public List<SaleVO> setShareMsg(List<SaleVO> saleList,String invite_no) {
		
		
		GoodVO vo1 =new GoodVO();
		for(int i=0; i<saleList.size();i++){
			GoodVO vo =new GoodVO();
			
			
			for(int j=0; j<saleList.get(i).getGoodList().size();j++){
				saleList.get(i).getGoodList().get(j).setShare(vo);
				try {
					vo1 = materialService.processShareInfo(saleList.get(i).getGoodList().get(j));
				} catch (Exception e) {
					e.printStackTrace();
					
					
				}
				if(saleList.get(i).getGoodList().get(j).getImg().indexOf("?")>-1){
					String arr[]=saleList.get(i).getGoodList().get(j).getImg().split("?");
					saleList.get(i).getGoodList().get(j).getShare().setImg(arr[0]+"?x-oss-process=image/resize,h_100");
				}else{
					saleList.get(i).getGoodList().get(j).getShare().setImg(saleList.get(i).getGoodList().get(j).getImg()+"?x-oss-process=image/resize,h_100");
				}
				saleList.get(i).getGoodList().get(j).getShare().setUrl(configDao.loadConfig("WECHAT_HOST")+"/goodDetail?good_id="+saleList.get(i).getGoodList().get(j).getGood_id()+"&ym_share_inviteno="+invite_no);
				saleList.get(i).getGoodList().get(j).getShare().setTitle(saleList.get(i).getGoodList().get(j).getName());
				saleList.get(i).getGoodList().get(j).getShare().setContent(configDao.loadConfig("SHARE_GOOD_DETAIL_CONTENT"));
				saleList.get(i).getGoodList().get(j).getShare().setMin_share_info(vo1.getStandard_list().get(0).getMin_share_info());
				saleList.get(i).getGoodList().get(j).getShare().setShare_info(vo1.getStandard_list().get(0).getShare_info());
			}
		}
		return saleList;
	}
}
